package com.lenovo.smarttraffic.database.dao;

import android.content.Context;

/**
 * author  张猛
 **/
public class DaoManager_UserInfo {
    private Context mContext;
    private static final String DB_NAME = "UserInfo.db";
    private volatile static DaoManager_UserInfo mInstance_UserInfo;
    private static DaoMaster mDaoMaster_UserInfo;
    private static DaoMaster.DevOpenHelper mHelper_UserInfo;
    private static DaoSession mDaoSession_UserInfo;

    public DaoManager_UserInfo() {
    }

    public static DaoManager_UserInfo getmInstance_UserInfo() {
        if (mInstance_UserInfo == null) {
            synchronized (DaoManager_UserInfo.class) {
                if (mInstance_UserInfo == null) {
                    mInstance_UserInfo = new DaoManager_UserInfo();
                }
            }
        }
        return mInstance_UserInfo;
    }

    public void init(Context context) {
        this.mContext = context;
    }



    public DaoMaster getDaoManager_UserInfo() {
        if (mDaoMaster_UserInfo == null) {
            mHelper_UserInfo = new DaoMaster.DevOpenHelper(mContext, DB_NAME, null);
            mDaoMaster_UserInfo= new DaoMaster(mHelper_UserInfo.getWritableDatabase());
        }
        return mDaoMaster_UserInfo;
    }




    public DaoSession getDaoSession_UserInfo() {
        if (mDaoSession_UserInfo == null) {
            if (mDaoMaster_UserInfo == null) {
                mDaoMaster_UserInfo = getDaoManager_UserInfo();
            }
            mDaoSession_UserInfo = mDaoMaster_UserInfo.newSession();
        }
        return mDaoSession_UserInfo;
    }

    public void closeConnection() {
        closeHelper();
        closeDaoSession();
    }

    public void closeHelper() {
        if (mHelper_UserInfo != null) {
            mHelper_UserInfo.close();
            mHelper_UserInfo = null;
        }
    }

    public void closeDaoSession() {
        if (mDaoSession_UserInfo != null) {
            mDaoSession_UserInfo.clear();
            mDaoSession_UserInfo = null;
        }
    }
}
